package com.breaktian.assemble.router;

import android.util.SparseArray;

/**
 * Created by keke.tian on 2017/7/27.
 * 路由错误表
 */

public class RouterError {
    private int code;
    private String msg;

    public RouterError(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    @Override
    public String toString() {
        return "RouterError{" + "code=" + code + ", msg='" + msg + '\'' +'}';
    }


    private static SparseArray<RouterError> errorMap = new SparseArray<>();

    public static final int ERROR_CODE_UNKNOWN = 0x00;
    public static final String ERROR_MSG_KNOWN = "未知错误";

    public static final int ERROR_CODE_NOT_SET_ACTIVITY_OR_CONTEXT = 0x01;
    public static final String ERROR_MSG_NOT_SET_ACTIVITY_OR_CONTEXT = "没有设置context,请先调用setContext或setActivity或setFragment方法";

    public static final int ERROR_CODE_NOT_SET_ACTIVITY = 0x02;
    public static final String ERROR_MSG_NOT_SET_ACTIVITY = "没有设置activity,请先调用setActivity或者setFragment方法, startActivityForResult需要Activity context";

    public static final int ERROR_CODE_JUMPFORRESULT_REQUEST_CODE_INVALID = 0x03;
    public static final String ERROR_MSG_JUMPFORRESULT_REQUEST_CODE_INVALID = "jumpForResult方法的requestCode必须大于等于0";

    public static final int ERROR_CODE_JUMP_TARGET_IS_NULL_OR_EMPTY = 0x04;
    public static final String ERROR_MSG_JUMP_TARGET_IS_NULL_OR_EMPTY = "跳转的target是null或空";

    public static final int ERROR_CODE_INVALID_URL_OR_SCHEMA = 0x05;
    public static final String ERROR_MSG_INVALID_URL_OR_SCHEMA = "非法的url或schema";

    public static final int ERROR_CODE_INVALID_PACKAGE_CONTEXT = 0x06;
    public static final String ERROR_MSG_INVALID_PACKAGE_CONTEXT = "startWithReflect 非法的packageContext,new Intent(mContext,clazz) 等于null";

    public static final int ERROR_CODE_INTENTACTION_IS_EMPTY = 0x07;
    public static final String ERROR_MSG_INTENTACTION_IS_EMPTY = "startWithAction intentAction is empty";

    public static final int ERROR_CODE_WEBVIEW_SCHEMA_NOT_SET = 0x08;
    public static final String ERROR_MSG_WEBVIEW_SCHEMA_NOT_SET = "webviewSchema 没有配置，请在XML中配置的webview schema";

    public static final int ERROR_CODE_WEBVIEW_RULE_IS_NULL = 0x09;
    public static final String ERROR_MSG_WEBVIEW_RULE_IS_NULL = "webview的路由没有配置，请在XML中配置的webview的路由规则";

    public static final int ERROR_CODE_WEBVIEW_URL_IS_EMPTY = 0x10;
    public static final String ERROR_MSG_WEBVIEW_URL_IS_EMPTY = "startWithHttp URL is empty";

    public static final int ERROR_CODE_JUMP_CANCELED_BY_INTERCEPTOR = 0x11;
    public static final String ERROR_MSG_JUMP_CANCELED_BY_INTERCEPTOR = "跳转行为被拦截器拦截";

    public static final int ERROR_CODE_SCHEMA_RULE_IS_NULL = 0x12;
    public static final String ERROR_MSG_SCHEMA_RULE_IS_NULL = "schema的路由没有配置，请在XML中配置的schema的路由规则";

    public static final int ERROR_CODE_URL_PARAMS_INVALID = 0x13;
    public static final String ERROR_MSG_URL_PARAMS_INVALID = "http或者schema的url参数格式不正确";
    public static final int ERROR_CODE_PACKAGE_INVALID = 0x14;
    public static final String ERROR_MSG_PACKAGE_INVALID = "路由表class字段配置错误 获取package错误";



    static {
        errorMap.put(ERROR_CODE_UNKNOWN, new RouterError(ERROR_CODE_UNKNOWN, ERROR_MSG_KNOWN));
        errorMap.put(ERROR_CODE_NOT_SET_ACTIVITY_OR_CONTEXT, new RouterError(ERROR_CODE_NOT_SET_ACTIVITY_OR_CONTEXT, ERROR_MSG_NOT_SET_ACTIVITY_OR_CONTEXT));
        errorMap.put(ERROR_CODE_NOT_SET_ACTIVITY, new RouterError(ERROR_CODE_NOT_SET_ACTIVITY, ERROR_MSG_NOT_SET_ACTIVITY));
        errorMap.put(ERROR_CODE_JUMPFORRESULT_REQUEST_CODE_INVALID, new RouterError(ERROR_CODE_JUMPFORRESULT_REQUEST_CODE_INVALID, ERROR_MSG_JUMPFORRESULT_REQUEST_CODE_INVALID));
        errorMap.put(ERROR_CODE_JUMP_TARGET_IS_NULL_OR_EMPTY, new RouterError(ERROR_CODE_JUMP_TARGET_IS_NULL_OR_EMPTY, ERROR_MSG_JUMP_TARGET_IS_NULL_OR_EMPTY));
        errorMap.put(ERROR_CODE_INVALID_URL_OR_SCHEMA, new RouterError(ERROR_CODE_INVALID_URL_OR_SCHEMA, ERROR_MSG_INVALID_URL_OR_SCHEMA));
        errorMap.put(ERROR_CODE_INVALID_PACKAGE_CONTEXT, new RouterError(ERROR_CODE_INVALID_PACKAGE_CONTEXT, ERROR_MSG_INVALID_PACKAGE_CONTEXT));
        errorMap.put(ERROR_CODE_INTENTACTION_IS_EMPTY, new RouterError(ERROR_CODE_INTENTACTION_IS_EMPTY, ERROR_MSG_INTENTACTION_IS_EMPTY));
        errorMap.put(ERROR_CODE_WEBVIEW_SCHEMA_NOT_SET, new RouterError(ERROR_CODE_WEBVIEW_SCHEMA_NOT_SET, ERROR_MSG_WEBVIEW_SCHEMA_NOT_SET));
        errorMap.put(ERROR_CODE_WEBVIEW_RULE_IS_NULL, new RouterError(ERROR_CODE_WEBVIEW_RULE_IS_NULL, ERROR_MSG_WEBVIEW_RULE_IS_NULL));
        errorMap.put(ERROR_CODE_WEBVIEW_URL_IS_EMPTY, new RouterError(ERROR_CODE_WEBVIEW_URL_IS_EMPTY, ERROR_MSG_WEBVIEW_URL_IS_EMPTY));
        errorMap.put(ERROR_CODE_JUMP_CANCELED_BY_INTERCEPTOR, new RouterError(ERROR_CODE_JUMP_CANCELED_BY_INTERCEPTOR, ERROR_MSG_JUMP_CANCELED_BY_INTERCEPTOR));
        errorMap.put(ERROR_CODE_SCHEMA_RULE_IS_NULL, new RouterError(ERROR_CODE_SCHEMA_RULE_IS_NULL, ERROR_MSG_SCHEMA_RULE_IS_NULL));
        errorMap.put(ERROR_CODE_URL_PARAMS_INVALID, new RouterError(ERROR_CODE_URL_PARAMS_INVALID, ERROR_MSG_URL_PARAMS_INVALID));
        errorMap.put(ERROR_CODE_PACKAGE_INVALID, new RouterError(ERROR_CODE_PACKAGE_INVALID, ERROR_MSG_PACKAGE_INVALID));

    }


    static RouterError get(int code) {
        return errorMap.get(code);
    }

}
